

$(function (){

    

   

    var winIndex='';
    var timer=null;
    var phone='';
    var codeSn='';
    phone = localStorage.getItem('lucky_phone') || '';


    var time = 60;
    $('#get-code').click(function () {//获取验证码

        if(time !=60 )return;
        phone = $('#phone').val();
        if(!phone.trim()){
            $.message.warning('请先输入手机号码');
            return;
        }
        if(!(/^1[3456789]\d{9}$/.test(phone))){
            $.message.warning('请正确输入手机号码');
            return;
        }
        $(this).text(`${time}s后重新发送`).css('color','#ccc')
        timer =  setInterval( ()=> {
            time -= 1;
            $(this).text(`${time}s后重新发送`)
            if(time == 0){
                clearInterval(timer);
                $(this).text(`获取验证码`).css('color','#3c90df')
                time = 60;
            }
        },1000);


        request(sendcode_api,{mobile:phone}).then((res)=>{
            // localStorage.setItem('lucky_phone',phone);
        })


    })

    $('.loginbtn').click(function () {

        phone = $('#phone').val();
        codeSn=  $('#code-sn').val();
        if(!phone.trim()){
            $.message.warning('请先输入手机号码');
            return;
        }
        if(!(/^1[3456789]\d{9}$/.test(phone))){
            $.message.warning('请正确输入手机号码');
            return;
        }
        /*if(!codeSn.trim()){
            $.message.warning('请先输入短信验证码');
            return;
        }*/
        clearInterval(timer);


        let type = $(this).attr('type');
        console.log(type);
        request(checkmobile_api,{mobile:phone,type:type}).then((res)=>{

            $('#login').css('display','none');
            localStorage.setItem('survey_phone',phone);
            Questionnaire(type);

        }).catch((res)=>{

            $.message.warning(`不在调研名单内`);

        });

    })

    $('.login-close').click(function () {
        $('#login').css('display','none')
    });

    $('.code-txt').click(function () {
        var survey_phone = localStorage.getItem('survey_phone');
        var value = $(this).attr('value')
        console.log(value);
        if(survey_phone){
            Questionnaire(value);
        }else {
            $('#login').css('display','flex')
        }

    });



});
